interface MathOperation {
    int operation(int a, int b);
}

interface MessageOperation {
    String getGreety(String name);
}

class Add implements MathOperation {
    @Override
    public int operation(int a, int b) {
        return a + b;
    }
}

class Sub implements MathOperation {
    @Override
    public int operation(int a, int b) {
        return a - b;
    }
}

class Div implements MathOperation {
    @Override
    public int operation(int a, int b) {
        int r = a / b;
        return r;
    }
}

public class Test {
    public static int MyOperation(int x, int y, MathOperation obj) {
        int r = obj.operation(x, y);
        return r;
    }
    public static void main(String[] args) {
        MathOperation obj = new Add();
        // 实现加法运算
        int r = obj.operation(1, 2);
        // 实现减法运算
        obj = new Sub();
        r = obj.operation(1, 2);
        // 实现乘法运算
        // 函数体部分省略了花括号和return关键字，如果函数体中有多个语句时，花括号就必须写出来
        obj = (x, y) -> x * y;
        /*obj = (x, y) -> {
            return x * y;
        };*/
        r = obj.operation(2, 3);
        System.out.println(r);
        obj = (x, y) -> {
            int rr = x / y;
            return rr;
        };
        r = obj.operation(6, 2);
        System.out.println(r);
        MessageOperation obj2 = name -> {
            return "Hello " + name;
        };
        MessageOperation obj4 = name -> "Hello " + name;
        // 进行加法运算
        int result = MyOperation(1, 2, new Add());
        // 进行减法运算
        result = MyOperation(1, 2, new Sub());
        // 乘法运算
        result = MyOperation(1, 2, (x, y) -> x * y);
        // 除法运算
        result = MyOperation(1, 2, (x, y) ->{
            int rrr= x * y;
            return rrr;
        });
    }
}
